#include<iostream>
using namespace std;
#define MAX 100000
int main() {
    char men[MAX][10];
    int head[MAX] = {}, face[MAX] = {}, num[MAX] = {};
    int n, m, i, j, flag;
    j = 1;
    cout << j;
    cin >> n >> m;

    for (i = 1; i <= n; i++) {
        cin >> head[i] >> men[i];
    }


    for (i = 1; i <= m; i++) {
        cin >> face[i] >> num[i];
        flag = 1;
        if ((head[i]) + (face[i]) > 0 && (head[i]) + (face[i]) < 2)
            flag = -1;
        j = (j + n + num[i] * flag) % n;
    }


    cout << men[j];
}